interface Employee {
    employeeName: string;
}
interface Product {
    soldBy: Employee;
    productName: string;
}

function randomArray(maxSize = 10): number[] {
    const randomN = Math.ceil(Math.random() * maxSize);
    const r: number[] = [];
    for (let i = 0; i < randomN; i++) {
        r.push(i);
    }
    return r;
}

function sellProducts(e: Employee): Array<Product> {
    return randomArray(10).map((idx) => {
        const p: Product = {
            soldBy: e,
            productName: `product-${idx}`,
        };
        return p;
    })
}

function flatten<T>(arrOfArr: T[][]): T[] {
    const res: T[] = [];
    for (const arr of arrOfArr) {
        arr.forEach(i => res.push(i));
    }
    return res;
}

const employees: Array<Employee> = randomArray(3).map(i => ({ employeeName: `employee-${i}` } as Employee));

const res1 = employees.map(e => sellProducts(e)) //Array<Array<Product>>
const res2 = employees.flatMap(e => sellProducts(e)) //Array<Product>

console.log("total from res1", flatten(res1).length);
console.log("total from res2", res2.length);

//map, flatMap, flatten
//map -> flatten === flatMap




